package com.gdust.hzx.manager.service.impl;

import com.gdust.hzx.manager.mapper.CategoryBrandMapper;
import com.gdust.hzx.manager.service.CategoryBrandService;
import com.gdust.hzx.model.dto.product.CategoryBrandDto;
import com.gdust.hzx.model.entity.product.Brand;
import com.gdust.hzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: CategoryBrandServiceImpl
 * Package: com.gdust.spzx.manager.service.impl
 * Description:
 *
 * @Author syun
 * @Create 2024/12/21 16:15
 * @Version 1.0
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {
    @Autowired
    private CategoryBrandMapper categoryBrandMapper;


    /***
     * 分页查询分类品牌
     * @param page 当前页
     * @param limit 每页记录数
     * @param categoryBrandDto 搜索条件
     * @return
     */
    @Override
    public PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto categoryBrandDto) {
        //使用PageHelper分页插件进行分页
        PageHelper.startPage(page,limit);
        //自定义方法：分页查询分类品牌
        List<CategoryBrand> list = categoryBrandMapper.findByPage(categoryBrandDto);
        //新建分页对象
        PageInfo<CategoryBrand> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 添加分类品牌
     * @param categoryBrand
     */
    @Override
    public void save(CategoryBrand categoryBrand) {
        //自定义查询：添加分类品牌
        categoryBrandMapper.save(categoryBrand);
    }

    /**
     * 修改分类品牌
     * @param categoryBrand
     */
    @Override
    public void updateById(CategoryBrand categoryBrand) {
        //自定义查询：修改分类品牌
        categoryBrandMapper.updateById(categoryBrand);
    }

    /**
     * 删除分类品牌
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        categoryBrandMapper.deleteById(id);
    }

    /**
     * 加载品牌数据
     * @param categoryId 品牌id
     * @return
     */
    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        //自定义查询：查询品牌数据
        return categoryBrandMapper.findBrandByCategoryId(categoryId);
    }
}
